<template>
  <div class="login">
    <div class="header" style="display: none">
      <div class="nav">
        <router-link to="/">
          <img
            src="../../assets/images/login/login-logo.png"
            alt="LOGO"
            class="logo"
          >
        </router-link>
      </div>
    </div>
    <div class="login-container">
      <svg-icon icon-class="login_left" class="login_panle_left"></svg-icon>
      <div class="login-container-f">
        <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          auto-complete="on"
          label-position="left"
        >
          <div class="content">
            <div class="main">
              <h3>登录 我的SP店铺</h3>
              <p class="login__tips">为获得最佳体验，强烈建议您使用谷歌浏览器</p>
              <el-form-item prop="userName">
                <span class="svg-container">
                  <svg-icon icon-class="user-custom" />
                </span>
                <el-input
                  v-model.trim="loginForm.userName"
                  name="userName"
                  type="text"
                  auto-complete="on"
                  placeholder="请输入邮箱"
                />
              </el-form-item>
              <el-form-item prop="password">
                <span class="svg-container">
                  <svg-icon icon-class="lock-custom" />
                </span>
                <el-input
                  :type="pwdType"
                  v-model.trim="loginForm.password"
                  name="password"
                  auto-complete="on"
                  placeholder="请输入密码"
                  @keyup.enter.native="handleLogin"
                />
                <span
                  class="show-pwd"
                  @click="showPwd"
                >
                  <svg-icon :icon-class="pwdType === 'password' ? 'eye' : 'eye-open'" />
                </span>
              </el-form-item>
              <el-form-item>
                <el-button
                  :loading="loading"
                  type="primary"
                  style="width:100%;"
                  @click.native.prevent="handleLogin"
                >
                  登录
                </el-button>
              </el-form-item>
              <div class="buttom_btn">
                 <el-button type="text" size="mini" @click="handleDetail()" class="button">
                 注册账号
                </el-button>
                <el-button type="text" size="mini" @click="handleDetailForget()" class="button_btn">
                 忘记密码
                </el-button>
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <footer class="footer">
        <div class="service-intro">
          <div class="friend-link">
            <div class="friend-link-item">
              <ul>
                <li>Shanghai Hongyou Trading Co., Ltd. </li>
<!--                <li><a href="https://beian.miit.gov.cn/">沪ICP备2021007013号-1</a></li>-->
              </ul>
            </div>
          </div>
        </div>
      </footer>
    </div>
  </div>
</template>

<script>
import md5 from 'js-md5';
import { mapGetters } from 'vuex';
export default {
    name: 'Login',
    computed: {
        ...mapGetters([
            'isMobile' // 从 Vuex store 获取移动设备状态
        ])
    },
    data () {
        return {
            loginForm: {
                userName: '',
                password: ''
            },
            loginRules: {
                userName: [{required: true, message: '请输入邮箱', trigger: 'blur'}],
                password: [
                    {required: true, message: '请输入密码', trigger: 'blur'}
                    // eslint-disable-next-line standard/object-curly-even-spacing
                    // {type: 'string', pattern: /^(?![A-Za-z]+$)(?![A-Z\d]+$)\S{8,}$/, message: '密码最少8位,并且至少包含1个字母和1个数字', trigger: 'blur' }
                ]
            },
            loading: false,
            pwdType: 'password',
            redirect: undefined
        };
    },
    /*    watch: {
        $route: {
            handler: function (route) {
                this.redirect = route.query && route.query.redirect;
            },
            immediate: true
        }
    }, */
    methods: {
        handleDetail () {
            this.$router.push({path: 'register'});
        },
        handleDetailForget () {
            this.$router.push({path: 'forget-password'});
        },
        showPwd () {
            if (this.pwdType === 'password') {
                this.pwdType = '';
            } else {
                this.pwdType = 'password';
            }
        },
        handleLogin () {
            this.$refs.loginForm.validate(valid => {
                if (valid) {
                    this.loading = true;
                    let params = {
                        userName: this.loginForm.userName,
                        password: md5(this.loginForm.password)
                    };
                    this.$store.dispatch('Login', params).then(() => {
                        this.loading = false;
                        console.log(this.isMobile);
                        if (this.isMobile) {
                            this.$router.push({name: 'order-list'});
                        } else {
                            this.$router.push({ path: this.redirect || '/' });
                        }
                    }).catch(() => {
                        this.loading = false;
                    });
                } else {
                    return false;
                }
            });
        }
    }
};
</script>

<style rel="stylesheet/scss" lang="scss">
$bg: #2d3a4b;
$light_gray: #fff;

.login{
  background-image: url("../../assets/images/login_background.jpg");
  margin: 0;
  padding: 0;
  background-size: cover;
  width: 100%;
  height: 100vh;
  min-height: 690px;
  position: relative;
  background-position: center;
}

/* reset element-ui css */
.login-container {
  position: absolute;
  top: 3vh;
  left: 2vw;
  width: 96vw;
  height: 94vh;
  background-color: #fffc;
  backdrop-filter: blur(5px);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  @media screen and (max-width: 1000px) {
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    border-radius: 0;
    padding: 20px;
    box-sizing: border-box;
    justify-content: center;
  }
  .login_panle_left{
    width: 40%;
    height: 60%;
    float: left;
    @media screen and (max-width: 1000px) {
      display: none;
    }
  }
  .login-container-f {
    width: 500px;
    background-color: #fff;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 2px 3px 7px #0003;
    background-image: linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.96) 0%,
            rgba(245, 245, 245, 0.96) 100%
    );
    @media screen and (max-width: 1000px) {
      width: 100%;
      padding: 20px;
      margin: 0;
      box-shadow: none;
      background: transparent;
    }
  }
  .el-form {
    width: 460px;
    border-radius: 10px;
    float: right;
    max-width: 100%;
    @media screen and (max-width: 1000px) {
      width: 100%;
      float: none;
      padding: 0 10px;
    }
  }
  .el-input {
    display: inline-block;
    height: 42px;
    width: 85%;
    @media screen and (max-width: 1000px) {
      width: 80%;
    }
    input {
      box-sizing: border-box;
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #000;
      height: 42px;
      line-height: normal;
      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
        -webkit-text-fill-color: #000 !important;
      }
    }
  }
  .buttom_btn{
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  .button{
     font-size: 14px;
     margin-right: 20px;
  }
  .button_btn{
    font-size: 14px;
    margin-left: 20px;
  }
  .el-form-item {
    border: 1px solid rgb(220, 223, 230);
    background: $light_gray;
    border-radius: 5px;
    color: #454545;
    &.foot-link {
      background: transparent;
      p {
        text-align: right;
        margin: 0;
        a {
          color: #1c73e7;
          &:first-child {
            margin-right: 10px;
          }
        }
      }
    }
  }
}
.contact-jx {
  .el-tabs {
    width: 320px;
    .el-tabs__nav {
      font-size: 16px;
      .el-tabs__item {
        height: auto;
        line-height: inherit;
        padding-bottom: 10px;
      }
      /*#tab-second{*/
      /*    margin-left: 80px;*/
      /*}*/
    }
  }
}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
$bg: rgba(75, 160, 240, 1);
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container {
  min-height: 690px;
  @media screen and (min-width: 1024px) {
    min-width: 990px;
  }
  .login-center-layout{
    background: #409eff;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    position: absolute;
    top:110px;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 1px 5px 1px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title {
    font-size: 26px;
    font-weight: 400;
    color: $light_gray;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .content {
    display: flex;
    .bg,
    .main {
      flex: 1;
    }
    .main {
      h3 {
        text-align: center;
        font-size: 24px;
        color: #333;
        margin-bottom: 20px;
        @media screen and (max-width: 1000px) {
          font-size: 20px;
          margin-bottom: 15px;
        }
      }
      .login__tips {
        text-align: center;
        font-size: 14px;
        color: #666;
        margin-bottom: 20px;
        @media screen and (max-width: 1000px) {
          font-size: 12px;
          margin-bottom: 15px;
        }
      }
      .el-button--primary {
        height: 42px;
        background: #409EFF;
        border-color: #409EFF;
        border-radius: 4px;
        font-size: 16px;
        @media screen and (max-width: 1000px) {
          height: 40px;
          font-size: 15px;
        }
      }
      .buttom_btn {
        display: flex;
        justify-content: space-between;
        margin-top: 15px;
        padding: 0 10px;
        .button, .button_btn {
          color: #409EFF;
          font-size: 14px;
          @media screen and (max-width: 1000px) {
            font-size: 13px;
          }
        }
      }
    }
  }
}
.header {
  width: 100%;
  height: 60px;
  background: rgba(0, 0, 0, 0.9);
  .nav {
    margin: 0% auto;
    width: 1200px;
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 60px;
    position: relative;
    .logo {
      display: block;
      vertical-align: middle;
    }
    ul {
      list-style: none;
      li {
        float: left;
        /*line-height: 35px;*/
        font-weight: bold;
        &:not(&:last-child) {
          margin-right: 15px;
        }
        a {
          text-decoration: none;
          color: #999999;
          padding-left: 28px;
          font-size: 16px;
          /*border-left: 1px solid #ccc;*/
          cursor: pointer;
          > svg {
            margin-right: 2px;
          }
          &.router-link-active {
            color: #fff;
          }
          &:hover {
            color: #fff;
          }
        }
      }
    }
    .r-link {
      position: absolute;
      right: 0;
      margin: 0;
      li {
        a {
          padding-left: 14px;
        }
        a.login {
          border-right: 1px solid #ccc;
          padding-right: 15px;
        }
        a > svg {
          color: #999;
        }
        a.link,
        a.link > svg {
          /*color: #fff;*/
        }
      }
    }
    .location {
      color: #999;
      position: relative;
      top: 6px;
      a {
        border-left: none;
        font-size: 14px;
      }
    }
  }
}
.footer {
  position: absolute;
  bottom: 20px;
  .service-intro {
    width: 100%;
    margin-top: 30px;
    .servece-type {
      margin: 15px auto;
      height: 200px;
      width: 1200px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      .servece-type-info {
        color: #666666;
        ul {
          list-style: none;
          li {
            font-size: 14px;
            cursor: pointer;
            line-height: 26px;
            &:first-child {
              font-size: 16px;
              line-height: 28px;
              font-weight: bold;
            }
          }
        }
      }
    }
    .friend-link {
      display: flex;
      align-items: center;
      width: 1200px;
      margin: 0px auto;
      color: #666;
      .friend-link-item {
        margin: 0px auto;
        ul {
          list-style: none;
          li {
            padding: 5px 0px;
            text-align: center;
          }
        }
        .link-item {
          padding: 0px 8px;
          cursor: pointer;
        }
        .link-last-item {
          border: none;
        }
      }
    }
    @media screen and (max-width: 1000px) {
      .friend-link{
        width: 100%;
      }
    }
  }
  .copyright {
    width: 100%;
    color: #666;
    line-height: 30px;
    text-align: center;
    a {
      color: #232323;
      font-size: 20px;
    }
  }
  .contact-jx {
    flex-basis: 320px;
    .qr {
      > div {
        display: inline-block;
        &:first-child {
          margin-right: 80px;
        }
      }
    }
    p {
      width: 104px;
      text-align: center;
      margin: 0;
      margin-top: 10px;
    }
  }
}
.loginPic {
  padding: 0 10px;
  display: flex;
  span {
    &:first-child {
      margin-right: 10px;
    }
  }
  p {
    text-align: center;
    margin: 0;
    margin-bottom: 5px;
  }
}
</style>
